/**
 * Author: w景洋.
 * Time: 2016/4/19 0019
 */
angular.module('service.goods', [
        "ngResource"
    ])
    .service('MenuGoodsService', MenuGoodsService)
    .service('GoodsService', GoodsService);
MenuGoodsService.$inject = ['$resource'];
function MenuGoodsService($resource) {
    var Menu = $resource(mallurl + 'menu/bygroup/:id', {}, {
        get: {cache: true, method: 'GET'},
        query: {cache: true, method: 'GET', isArray: true}
    });
    //var Menu = $resource(mallurl+'/menu/:id', {}, {
    //    get: {cache: true, method: 'GET'},
    //    query: {cache: true, method: 'GET', isArray: true}
    //});
    //根据店铺id获取商品列表
    this.getMenuByShopid = function (shopid) {
        var goodsList = Menu.query({id: shopid,seq:0});
        return goodsList;
    }
}

GoodsService.$inject = ['$resource'];
function GoodsService($resource) {
    var Goods = $resource(mallurl + 'goods/:id');
    var GoodsSearch = $resource(mallurl + 'goods/bykeyword/:keyword');

    //查询商品详情
    this.getGoodsByGoodsId = function (goodsid) {
        return Goods.get({id: goodsid});
    };

    //搜索商品
    this.queryGoodsListByKeyword = function (keyword) {
        return GoodsSearch.query({keyword: keyword});
    };
    //通过商品id获取商品sku
    this.querySku = function(goodsid){
        var resource = $resource(mallurl + 'goodssku/bygoods/:goodsid',{},{
            get: {cache: true, method: 'GET'},
            query: {cache: true, method: 'GET', isArray: true}
        });
        return resource.query({goodsid:goodsid});
    };
    //通过店铺id和条码获取商品信息
    this.getByBarcode = function(shopid,barcode){
        var resource = $resource(mallurl + "goods/shop/:shopid/bybarcode/:barcode");
        return resource.get({shopid:shopid,barcode:barcode});
    }
}
